package org.fullhappy;


import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;

import org.fullhappy.entity.EbookFormat;
import org.fullhappy.library.dao.EbookFormatDAO;
import org.fullhappy.library.service.EbookService;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@ManagedBean
@SessionScoped
public class HelloBean implements Serializable {

	private static final long serialVersionUID = 1L;

	private String name;
	private short id;
	List<SelectItem> items = new ArrayList<SelectItem>();
	EbookService ebookService = new EbookService();

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	
	public List<SelectItem> getItems() {
		return items;
	}

	public void setItems(List<SelectItem> items) {
		this.items = items;
	}

	public String p(int i) {
		return i+""+i;
		
	}
	
	public String createEbookFormat(){
		EbookFormat ebookFormat = new EbookFormat();
		ebookFormat.setTitle(name);
		try {
			ebookService.create(ebookFormat);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		items = ebookService.getListSelectFormatItems();
		return "welcome";
	}

}